package com.yj.web;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.yj.util.Gd;
import com.yj.vo.JsonResult;

import com.yj.service.IRegionService;

import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author yj
 * @since 2020-08-24
 */
@RestController
@RequestMapping("/region")
public class RegionController {

	@Autowired
	IRegionService regionService;

	// 返回经纬度
	@PostMapping("/jwaddr")
	public JsonResult jwaddr(String address) {
		JsonResult jsonResult = new JsonResult(false, "");
		double[] arr = Gd.addressToGPS(address);
		if (arr.length == 2) {
			jsonResult.setSuccess(true);
			jsonResult.setData("jindu", arr[0]);
			jsonResult.setData("weidu", arr[1]);
		} else {
			jsonResult.setMessage("获取经纬度失败");
		}

		return jsonResult;

	}

	// 查询所有省份
	@PostMapping("/getpros")
	public JsonResult getProvnice() {
		return regionService.AllProvince();
	}

	// 根据省份查询所有市
	@PostMapping("/getcitys")
	public JsonResult getCitys(@RequestParam("pro") String provnice) {
		return regionService.Allcity(provnice);
	}

	// 查询热门城市
	@PostMapping("/hotcitys")
	public JsonResult getHotCitys() {
		return regionService.Houcity();
	}

}
